//
//  InfoMgr.m
//  AirTicket
//
//  Created by imac.bmw on 11-1-4.
//  Copyright 2011 aircococ. All rights reserved.
//

#import "InfoMgr.h"
//#import "CellNeedData.h"

@implementation InfoMgr
@synthesize dataList;

-(void)loadDataList
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo.plist"];
	NSFileManager *fM=[NSFileManager defaultManager];
	//NSLog(@"file path = %@",accountFilename);
	if(![fM fileExistsAtPath:accountFilename])
	{
		self.dataList = [NSMutableDictionary dictionary];
	}
	else
	{
		self.dataList = [NSMutableDictionary dictionaryWithContentsOfFile:accountFilename];
	}
}

-(void)saveDataList
{
//	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//	NSString *documentsDirectory = [paths objectAtIndex:0];
//	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo.plist"];
//	//[NSKeyedArchiver archiveRootObject:data toFile:accountFilename];
//	//[self.dataList writeToFile:accountFilename atomically:NO];
	
}

-(void)saveData:(id)data {

	//CellNeedData *newData = [data retain];
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo"];
	[NSKeyedArchiver archiveRootObject:data toFile:accountFilename];
	
}

-(id)getData{
	
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *accountFilename=[documentsDirectory stringByAppendingPathComponent:@"allInfo"];
	//[NSKeyedArchiver archiveRootObject:data toFile:accountFilename];
	id object = [NSKeyedUnarchiver unarchiveObjectWithFile:accountFilename];
	return object;
}

-(void)deleteDateForKey:(NSString *)key {

	//id object = [self.dataList objectForKey:key];
	[self.dataList removeObjectForKey:key];
}

-(void)logout {

	[self.dataList removeAllObjects];
}

-(void)dealloc
{
	[self.dataList release];
	[super dealloc];
}

@end
